package com.danjinwulian.device.service.impl;

import com.danjinwulian.common.constant.UserConstants;
import com.danjinwulian.common.core.domain.entity.IotProduct;
import com.danjinwulian.common.utils.StringUtils;
import com.danjinwulian.device.mapper.IotProductMapper;
import com.danjinwulian.device.service.IIotProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 产品 业务层处理
 * 
 * @author ken.h
 */
@Service
public class IIotProductServiceImpl implements IIotProductService
{
    private static final Logger log = LoggerFactory.getLogger(IIotProductServiceImpl.class);

    @Autowired
    private IotProductMapper productMapper;

    @Override
    public List<IotProduct> selectProductList(IotProduct iotProduct) {
        return productMapper.selectProductList(iotProduct);
    }

    @Override
    public int selectProductCount() {
        return productMapper.selectProductCount();
    }

    @Override
    public String checkProductNameUnique(IotProduct iotProduct) {
        String productId = StringUtils.isNull(iotProduct.getProductId()) ? "" : iotProduct.getProductId();
        IotProduct info = productMapper.checkProductNameUnique(iotProduct.getProductName());
        if (StringUtils.isNotNull(info) && info.getProductId().equals(productId))
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public IotProduct selectProductById(String productId) {
        return productMapper.selectProductById(productId);
    }

    @Override
    public int insertProduct(IotProduct iotProduct) {
        return productMapper.insertProduct(iotProduct);
    }

    @Override
    public int updateProduct(IotProduct iotProduct) {
        return productMapper.updateProduct(iotProduct);
    }

    @Override
    public int deleteProductById(String productId) {
        return productMapper.deleteProductById(productId);
    }

    @Override
    public int deleteProductByIds(String[] productIds) {
        return productMapper.deleteProductByIds(productIds);
    }
}
